// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import PowerControl from "../PublicScript/PowerControl";
import GameData_red_blue_man from "./GameData_red_blue_man";
import ControlScript from "../PublicScript/ControlScript";
import FlyPower from "./FlyPower";

const {ccclass, property} = cc._decorator;

@ccclass
export default class AddPower extends cc.Component {


    // onLoad () {}

    start () {
        this.node.zIndex = 200;
    }

    onclick(e,d){
        if(parseInt(d) == 1){
            this.node.destroy();
        }

        if(parseInt(d) == 2){
            GameData_red_blue_man.showVideo({callback:()=>{
                    PowerControl.addPower(5);
                    let pos2 =cc.find("Canvas/power").children[0].children[0].convertToWorldSpaceAR(cc.v2(0,0));
                    let pos1 = this.node.convertToWorldSpaceAR(cc.v2(0,0));
                    ControlScript.instantiate("flyPower",(res)=>{
                        res.getComponent(FlyPower).init(pos1, pos2, ()=>{

                        }, true)
                    })
                    this.node.destroy();
                }, name: "加体力"})
        }
    }

    // update (dt) {}
}
